﻿-- =============================================
-- Script Template
-- =============================================

CREATE PROCEDURE P_TrendChart_PL5_HMFB  --排列五号码分布图

AS

set nocount on
 
Create table #LotteryNumberListPL5(id int identity(1,1),Isuse varchar(20),LotteryNumber varchar(100),
		W_0 int,W_1 int,W_2 int,W_3 int,W_4 int,W_5 int,W_6 int,W_7 int,W_8 int,W_9 int,
		Q_0 int,Q_1 int,Q_2 int,Q_3 int,Q_4 int,Q_5 int,Q_6 int,Q_7 int,Q_8 int,Q_9 int,
		B_0 int,B_1 int,B_2 int,B_3 int,B_4 int,B_5 int,B_6 int,B_7 int,B_8 int,B_9 int,
		S_0 int,S_1 int,S_2 int,S_3 int,S_4 int,S_5 int,S_6 int,S_7 int,S_8 int,S_9 int,
		G_0 int,G_1 int,G_2 int,G_3 int,G_4 int,G_5 int,G_6 int,G_7 int,G_8 int,G_9 int)

declare @cur cursor 
declare @Isuse varchar(20), @WinLotterNumber varchar(100), @id int 

declare @W_0 int,@W_1 int,@W_2 int,@W_3 int,@W_4 int,@W_5 int,@W_6 int,@W_7 int,@W_8 int,@W_9 int
declare @Q_0 int,@Q_1 int,@Q_2 int,@Q_3 int,@Q_4 int,@Q_5 int,@Q_6 int,@Q_7 int,@Q_8 int,@Q_9 int
declare @B_0 int,@B_1 int,@B_2 int,@B_3 int,@B_4 int,@B_5 int,@B_6 int,@B_7 int,@B_8 int,@B_9 int
declare @S_0 int,@S_1 int,@S_2 int,@S_3 int,@S_4 int,@S_5 int,@S_6 int,@S_7 int,@S_8 int,@S_9 int
declare @G_0 int,@G_1 int,@G_2 int,@G_3 int,@G_4 int,@G_5 int,@G_6 int,@G_7 int,@G_8 int,@G_9 int
declare  @W INT ,@Q INT ,@B INT,@S INT,@G INT

Create table #tb(id int,PlayNo varchar(20),WinLotteryNumber varchar(100))

	insert into #tb select top 100 Id,PlayNo,WinLotteryNumber from pm_plays where WinLotteryNumber <> '' and LotteryID = 64 order by id desc


set @G_0 = 0 set @G_1 = 0 set @G_2 = 0 set @G_3 = 0 set @G_4 = 0 set @G_5 = 0 set @G_6 = 0  set @G_7 = 0 set @G_8 = 0 set @G_9 = 0 
set @S_0 = 0 set @S_1 = 0 set @S_2 = 0 set @S_3 = 0 set @S_4 = 0 set @S_5 = 0 set @S_6 = 0  set @S_7 = 0 set @S_8 = 0 set @S_9 = 0
set @B_0 = 0 set @B_1 = 0 set @B_2 = 0 set @B_3 = 0 set @B_4 = 0 set @B_5 = 0 set @B_6 = 0  set @B_7 = 0 set @B_8 = 0 set @B_9 = 0
set @Q_0 = 0 set @Q_1 = 0 set @Q_2 = 0 set @Q_3 = 0 set @Q_4 = 0 set @Q_5 = 0 set @Q_6 = 0  set @Q_7 = 0 set @Q_8 = 0 set @Q_9 = 0 
set @W_0 = 0 set @W_1 = 0 set @W_2 = 0 set @W_3 = 0 set @W_4 = 0 set @W_5 = 0 set @W_6 = 0  set @W_7 = 0 set @W_8 = 0 set @W_9 = 0

set @cur = cursor FAST_FORWARD for select PlayNo,WinLotteryNumber from #tb order by id asc

open @cur

fetch next from @cur into @Isuse, @WinLotterNumber

while @@fetch_status=0
begin

SET @W = SUBSTRING(@WinLotterNumber,1,1)
SET @Q = SUBSTRING(@WinLotterNumber,2,1)	
set @B = Substring(@WinLotterNumber,3,1) 
set @S = Substring(@WinLotterNumber,4,1) 
set @G = Substring(@WinLotterNumber,5,1)	

set @G_0 = @G_0 +1  set @G_1 =@G_1 +1 set @G_2 =@G_2 +1 set @G_3 =@G_3 +1 set  @G_4 =@G_4 +1 set @G_5 =@G_5 +1 set  @G_6 =@G_6 +1 set  @G_7 =@G_7 +1 set  @G_8 =@G_8 +1 set  @G_9 =@G_9 +1 
set @S_0 = @S_0 +1  set @S_1 =@S_1 +1 set @S_2 = @S_2 +1 set @S_3 = @S_3 +1 set @S_4 = @S_4 +1 set @S_5 = @S_5 +1 set @S_6 = @S_6 +1  set @S_7 = @S_7 +1 set @S_8 =@S_8 +1 set @S_9 =@S_9 +1
set @B_0 = @B_0 + 1 set @B_1 =@B_1 + 1 set @B_2 = @B_2 + 1 set @B_3 = @B_3 + 1 set @B_4 = @B_4 + 1 set @B_5 = @B_5 + 1 set @B_6 = @B_6 + 1  set @B_7 = @B_7 + 1 set @B_8 = @B_8 + 1 set @B_9 = @B_9 + 1 
set @Q_0 = @Q_0 +1  set @Q_1 =@Q_1 +1 set @Q_2 = @Q_2 +1 set @Q_3 = @Q_3 +1 set @Q_4 = @Q_4 +1 set @Q_5 = @Q_5 +1 set @Q_6 = @Q_6 +1  set @Q_7 = @Q_7 +1 set @Q_8 =@Q_8 +1 set @Q_9 =@Q_9 +1
set @W_0 = @W_0 + 1 set @W_1 =@W_1 + 1 set @W_2 = @W_2 + 1 set @W_3 = @W_3 + 1 set @W_4 = @W_4 + 1 set @W_5 = @W_5 + 1 set @W_6 = @W_6 + 1  set @W_7 = @W_7 + 1 set @W_8 = @W_8 + 1 set @W_9 = @W_9 + 1 

IF(@W = 0)
BEGIN
	SET @W_0 = 0
END

IF(@W = 1)
BEGIN
	SET @W_1 = 0
END

IF(@W = 2)
BEGIN
	SET @W_2 = 0
END

IF(@W = 3)
BEGIN
	SET @W_3 = 0
END

IF(@W = 4)
BEGIN
	SET @W_4 = 0
END

IF(@W = 5)
BEGIN
	SET @W_5 = 0
END

IF(@W = 6)
BEGIN
	SET @W_6 = 0
END

IF(@W = 7)
BEGIN
	SET @W_7 = 0
END

IF(@W = 8)
BEGIN
	SET @W_8 = 0
END

IF(@W = 9)
BEGIN
	SET @W_9 = 0
END

IF(@Q = 0)
BEGIN
	SET @Q_0 = 0
END

IF(@Q = 1)
BEGIN
	SET @Q_1 = 0
END

IF(@Q = 2)
BEGIN
	SET @Q_2 = 0
END

IF(@Q = 3)
BEGIN
	SET @Q_3 = 0
END

IF(@Q = 4)
BEGIN
	SET @Q_4 = 0
END

IF(@Q = 5)
BEGIN
	SET @Q_5 = 0
END

IF(@Q = 6)
BEGIN
	SET @Q_6 = 0
END

IF(@Q = 7)
BEGIN
	SET @Q_7 = 0
END

IF(@Q = 8)
BEGIN
	SET @Q_8 = 0
END

IF(@Q = 9)
BEGIN
	SET @Q_9 = 0
END

IF(@B =0)
BEGIN
	SET @B_0 =0
END

IF(@B =1)
BEGIN
	SET @B_1 =0
END

IF(@B =2)
BEGIN
	SET @B_2 =0
END

IF(@B =3)
BEGIN
	SET @B_3 =0
END

IF(@B =4)
BEGIN
	SET @B_4 =0
END

IF(@B =5)
BEGIN
	SET @B_5 =0
END

IF(@B =6)
BEGIN
	SET @B_6 =0
END

IF(@B =7)
BEGIN
	SET @B_7 =0
END

IF(@B =8)
BEGIN
	SET @B_8 =0
END

IF(@B =9)
BEGIN
	SET @B_9 =0
END

if(@G = 0)
begin
	set @G_0 =0
end

if(@G = 1)
begin
	set @G_1 =0
end

if(@G = 2)
begin
	set @G_2 =0
end

if(@G = 3)
begin
	set @G_3 =0
end

if(@G = 4)
begin
	set @G_4 =0
end

if(@G = 5)
begin
	set @G_5 =0
end

if(@G = 6)
begin
	set @G_6 =0
end   
 
if(@G = 7)
begin
	set @G_7 =0
end   

if(@G = 8)
begin
	set @G_8 =0
end   

if(@G = 9)
begin
	set @G_9 =0
end

if(@S = 0)
begin
	set @S_0 =0
end

if(@S = 1)
begin
	set @S_1 =0
end

if(@S = 2)
begin
	set @S_2 =0
end

if(@S = 3)
begin
	set @S_3 =0
end

if(@S = 4)
begin
	set @S_4 =0
end

if(@S = 5)
begin
	set @S_5 =0
end

if(@S = 6)
begin
	set @S_6 =0
end   
 
if(@S = 7)
begin
	set @S_7 =0
end   
if(@S = 8)
begin
	set @S_8 =0
end 
  
if(@S = 9)
begin
	set @S_9 =0
end

if(@B = 0)
begin
	set @B_0 =0
end

if(@B = 1)
begin
	set @B_1 =0
end
if(@B = 2)
begin
	set @B_2 =0
end
if(@B = 3)
begin
	set @B_3 =0
end

if(@B = 4)
begin
	set @B_4 =0
end

if(@B = 5)
begin
	set @B_5 =0
end

if(@B = 6)
begin
	set @B_6 =0
end    

if(@B = 7)
begin
	set @B_7 =0
end   

if(@B = 8)
begin
	set @B_8 =0
end  

if(@B = 9)
begin
	set @B_9 =0
end 

insert into #LotteryNumberListPL5 values (@Isuse, @WinLotterNumber,
		@W_0, @W_1,@W_2,@W_3,@W_4,@W_5,@W_6,@W_7,@W_8,@W_9,
		@Q_0, @Q_1,@Q_2,@Q_3,@Q_4,@Q_5,@Q_6,@Q_7,@Q_8,@Q_9,
		@B_0 ,@B_1,@B_2 ,@B_3 ,@B_4 ,@B_5,@B_6 ,@B_7 ,@B_8,@B_9,
		@S_0 ,@S_1,@S_2 ,@S_3,@S_4,@S_5 ,@S_6 ,@S_7 ,@S_8 ,@S_9 ,
		@G_0 ,@G_1 ,@G_2 ,@G_3 ,@G_4 ,@G_5 ,@G_6 ,@G_7 ,@G_8 ,@G_9 )
						 	 				
fetch next from @cur into @Isuse, @WinLotterNumber

end

close @cur

select * from #LotteryNumberListPL5

GO

exec P_TrendChart_PL5_HMFB
